﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace FlexPlatform.Shared.GeneralUseObjects
{
    using FlexPlatform.GeneralUse;

    /// <summary>
    /// Gegeneric implementation of Property Grup
    /// </summary>
    public class PropertyGroup<T> : PropertyGroup
    {
        private List<Expression<Func<T, object>>> properties;

        public PropertyGroup() : base()
        {
            properties = new List<Expression<Func<T, object>>>();
        }

        public void AddProperty(Expression<Func<T, object>> propertyPath)
        {
            properties.Add(propertyPath);
            this.AddProperty(ReflectionHelper.GetPropertyName(propertyPath));
        }

        public override void AddProperty(string propertyName)
        {
            throw new InvalidOperationException("Cannot use non-generic method from generic instance!");
        }

        public IEnumerable<Expression<Func<T, object>>> GetProperties()
        {
            return properties;
        }
    }

    /// <summary>
    /// Non generic implementation of Property Grup
    /// </summary>
    public class PropertyGroup
    {
        private readonly List<string> propertyNames;

        public PropertyGroup()
        {
            propertyNames = new List<string>();
        }

        public virtual void AddProperty(string propertyName)
        {
            propertyNames.Add(propertyName);
        }

        public IEnumerable<string> GetProperyNames()
        {
            return propertyNames;
        }

        public bool ContainsProperty(string propertyName)
        {
            return propertyNames.Contains(propertyName);
        }
    }
}
